<template>
	<view>
		<view class="">
			<img v-if="login_img.topimg" :src="url + login_img.topimg" alt="" class="" style="width: 100%;height:360rpx;" />
		</view>
		
		
		<view class="cont">
			<view class="ce">
				<input type="text" v-model="mobile" placeholder="请输入登录账号/手机号码" />
			</view>
			<view class="ce">
				<input type="password" v-model="password" placeholder="请输入登录密码" />
			</view>
			<view class="bts" @click="sub">
				立即登录
			</view>
			<view class="ts">
				<button class="item record" open-type="getPhoneNumber" @getphonenumber="cs_getphonenumber"
					style="border: none;background: #fff;width: 88%;">
				
					手机号码一键登录
				
				</button>
				
			</view>
		</view>
		
		
		
		
		
		
		
	<!-- 	<view class="" style="font-size: 40rpx;text-align: center;margin-top: 20rpx;">
			-请选择不同身份入口登录-
		</view> -->
		<!-- 城市服务方 -->
	<!-- 	
		<view class="item" @click="cs_center" style="margin-top: 50rpx;width: 87%;" v-if="Object.keys(userinfo).length > 0">
			<img :src="url + imglist[1]" alt="" class="imgs" />
		</view>
		 -->
		
		
		
		
		
		
		<!-- <button v-if="pass_login == 0 && Object.keys(userinfo).length <= 0" class="item " open-type="getPhoneNumber" @getphonenumber="cs_getphonenumber"
			style="border: none;background: #fff;width: 88%;">
		
			<img :src="url + imglist[1]" alt="" class="imgs" />
		
		</button>
		<button v-else class="item " @getphonenumber="pass"
			style="border: none;background: #fff;width: 88%;">
		
			<img :src="url + imglist[1]" alt="" class="imgs" />
		
		</button> -->
		
		
	
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				imglist: [
					'wechatimg/ysd.png',
					'wechatimg/hhr.png',
					'wechatimg/hzd.png',
					'wechatimg/logintop.png',
				],
				hz_userinfo: {}, // 用户
				clinic_userinfo: {}, // 医生
				userinfo:{},// 合伙人
				pass_login:0,
				system_type:1,
				mobile:'',
				password:'',
				login_img:{
					topimg:'',
					city_img:'',
					clinic_img:'',
					user_img:'',
				}
			}
		},
		onShow() {
			
			this.hz_userinfo = uni.getStorageSync('hz_userinfo')
			this.clinic_userinfo = uni.getStorageSync('clinic_userinfo')
			this.userinfo = uni.getStorageSync('userinfo')
		},
		onLoad() {
			var that = this
			// 先获取是否开启了账号密码登录
			uni.request({
				url: that.global.url+'api/index/index',
				method: 'POST',
				data: {
				  
				},
				success(res) {
				    let result = res.data
				    console.log(result)
				    if(result.code == 1){
				       that.pass_login = result.data.pass_login
				    }else{
				        uni.showToast({
				            title: result.msg,
				            icon:'none'
				        })
				    }
				},complete() {
					uni.hideLoading()
				}
			})
			this.getbg()
		},
		methods: {
			getbg(){
				var that = this
				// 获取登录背景图
				uni.request({
					url: that.global.url + 'api/index/loginbg',
					method: 'POST',
					data: {
				
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.login_img = result.data
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'none'
							})
						}
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			sub(){
				let that = this
				let params = {
					mobile:that.mobile,
					password:that.password
				}
				uni.showLoading({
					title:'加载中...'
				})
				uni.request({
					url: that.global.url + 'api/user/mobile_pass_login',
					method: 'POST',
					data: {
						mobile: that.mobile,
						password: that.password
					},
					success(res) {
						let result = res.data
						console.log(result)
						// return false;
						if (result.code == 1) {
							// 存用户信息
							uni.setStorageSync('userinfo', result.data.userinfo)
							// 存用户信息
							uni.setStorageSync('token', result.data.userinfo.token)
							uni.redirectTo({
							  url: '/pages/personalCenter/personalCenter'
							});
							// that.cs_center()
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'none'
							})
						}
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			// 携带账号密码登录
			pass(){
				uni.navigateTo({
					url:'/pages/login/passlogin'
				})
			},
			ys_center(){
				uni.navigateTo({
					url:'/pages/device/clinic'
				})
			},
			// 去患者个人中心
			tocenter() {

				// uni.setStorageSync('token',uni.getStorageSync('lyk_token'))
				// uni.setStorageSync('userinfo',uni.getStorageSync('lyk_userinfo'))
				// uni.setStorageSync('system_type',4)
				uni.navigateTo({
					url: '/pages/hz_my/hz_my'
				});

			},
			
			cs_center(){
				uni.navigateTo({
					url: '/pages/personalCenter/personalCenter'
				});
			},
			
			
			// 城市服务放登录
			cs_getphonenumber (e) {
				console.log(e)
				var that = this
				uni.showLoading({
					title:'加载中...'
				})
				
				
				
				uni.login({
				  success: function (loginRes) {
				    console.log(loginRes);
					uni.request({
						url: that.global.url+'api/user/get_phone',
						method: 'POST',
						data: {
						    code:e.detail.code,
							openidcode:loginRes.code
						},
						success(res) {
						    let result = res.data
						    console.log(result)
						    if(result.code == 1){
								// that.login(18553083165)
						       that.login(result.data)
						    }else{
						        uni.showToast({
						            title: result.msg,
						            icon:'none'
						        })
						    }
						},complete() {
							uni.hideLoading()
						}
					})
				  }
				});
				// this.login(18143079335)
			},
			login(mobile){
				var that = this
				uni.showLoading({
					title:'加载中...'
				})
				uni.request({
					url: this.global.url+'api/user/mobilelogin',
					method: 'POST',
					data: {
					    mobile:mobile,
						
					},
					success(res) {
					    let result = res.data
					    console.log(result)
					    if(result.code == 1){
					        // 存用户信息
					        uni.setStorageSync('userinfo', result.data.userinfo)
							uni.setStorageSync('system_type', result.data.userinfo.system_type)
							// 存用户信息
							uni.setStorageSync('token', result.data.userinfo.token)
							that.cs_center()
					    }else{
					        uni.showToast({
					            title: result.msg,
					            icon:'none'
					          })
					    }
					},complete() {
						uni.hideLoading()
					}
				})
			},
			

		}
	}
</script>

<style>
	.bts{
		width: 94%;
		padding: 20rpx;
		margin: 0px auto;
		text-align: center;
		background-color: #1262DB;
		margin-top: 50rpx;
		color: #fff;
		border-radius: 10rpx;
	}
	.cont{
		width: 80%;
		padding: 20rpx;
		margin: 0px auto;
		display: flex;
		flex-direction: column;
	}
	.ce{
		padding: 20rpx;
		border: 1px solid #ccc;
		border-radius: 10rpx;
		margin-top: 30rpx;
	}
	.ts{
		color: #888888;
		    margin-top: 30rpx;
		    font-size: 26rpx;
		    text-align: center;
	}
	.item {
		width: 88%;
		color: #888888;
		    margin-top: 30rpx;
		    font-size: 26rpx;
		    text-align: center;

		margin: 0px auto;
		
	}
*:focus { outline: none; }
	.imgs {
		height: 100%;
		width: 100%;
	}
.record::after {
  border: none;
}
	button {
		margin: 0;
		padding: 0;
		border: none;
		background: none;
		font-family: inherit;
		font-size: inherit;
		cursor: pointer;
		outline: none;
	}
</style>